home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / main / slew.c < prev    next >
C/C++ Source or Header  |  1998-03-03  |  8KB  |  257 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: /usr/CVS/descent/main/slew.c,v $
  15.  * $Revision: 1.1.1.1 $
  16.  * $Author: nobody $
  17.  * $Date: 1998/03/03 15:12:30 $
  18.  * 
  19.  * Basic slew system for moving around the mine
  20.  * 
  21.  * $Log: slew.c,v $
  22.  * Revision 1.1.1.1  1998/03/03 15:12:30  nobody
  23.  * reimport after crash from backup
  24.  *
  25.  * Revision 1.1.1.1  1998/02/13  20:21:04  hfrieden
  26.  * Initial Import
  27.  *
  28.  * Revision 2.0  1995/02/27  11:29:32  john
  29.  * New version 2.0, which has no anonymous unions, builds with
  30.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  31.  * 
  32.  * Revision 1.34  1995/02/22  14:23:28  allender
  33.  * remove anonymous unions from object structure
  34.  * 
  35.  * Revision 1.33  1995/02/22  13:24:26  john
  36.  * Removed the vecmat anonymous unions.
  37.  * 
  38.  * Revision 1.32  1994/09/10  15:46:42  john
  39.  * First version of new keyboard configuration.
  40.  * 
  41.  * Revision 1.31  1994/08/31  18:29:58  matt
  42.  * Made slew work with new key system
  43.  * 
  44.  * Revision 1.30  1994/08/31  14:10:48  john
  45.  * Made slew go faster.
  46.  * 
  47.  * Revision 1.29  1994/08/29  19:16:38  matt
  48.  * Made slew object not have physics movement type, so slew objects don't
  49.  * get bumped.
  50.  * 
  51.  * Revision 1.28  1994/08/24  18:59:59  john
  52.  * Changed key_down_time to return fixed seconds instead of
  53.  * milliseconds.
  54.  * 
  55.  * Revision 1.27  1994/07/01  11:33:05  john
  56.  * Fixed bug with looking for stick even if one not present.
  57.  * 
  58.  * Revision 1.26  1994/05/20  11:56:33  matt
  59.  * Cleaned up find_vector_intersection() interface
  60.  * Killed check_point_in_seg(), check_player_seg(), check_object_seg()
  61.  * 
  62.  * Revision 1.25  1994/05/19  12:08:41  matt
  63.  * Use new vecmat macros and globals
  64.  * 
  65.  * Revision 1.24  1994/05/14  17:16:18  matt
  66.  * Got rid of externs in source (non-header) files
  67.  * 
  68.  * Revision 1.23  1994/05/03  12:26:38  matt
  69.  * Removed use of physics_info var rotvel, which wasn't used for rotational
  70.  * velocity at all.
  71.  * 
  72.  * Revision 1.22  1994/02/17  11:32:34  matt
  73.  * Changes in object system
  74.  * 
  75.  * Revision 1.21  1994/01/18  14:03:53  john
  76.  * made joy_get_pos use the new ints instead of
  77.  * shorts.
  78.  * 
  79.  * Revision 1.20  1994/01/10  17:11:35  mike
  80.  * Add prototype for check_object_seg
  81.  * 
  82.  * Revision 1.19  1994/01/05  10:53:38  john
  83.  * New object code by John.  
  84.  * 
  85.  * Revision 1.18  1993/12/22  15:32:50  john
  86.  * took out previos code that attempted to make
  87.  * modifiers cancel keydowntime.
  88.  * 
  89.  * Revision 1.17  1993/12/22  11:41:56  john
  90.  * Made so that keydowntime recognizes editor special case!
  91.  * 
  92.  * Revision 1.16  1993/12/14  18:13:52  matt
  93.  * Made slew work in editor even when game isn't in slew mode
  94.  * 
  95.  * Revision 1.15  1993/12/07  23:53:39  matt
  96.  * Made slew work in editor even when game isn't in slew mode
  97.  * 
  98.  * Revision 1.14  1993/12/05  22:47:49  matt
  99.  * Reworked include files in an attempt to cut down on build times
  100.  * 
  101.  * Revision 1.13  1993/12/01  11:44:14  matt
  102.  * Chagned Frfract to FrameTime
  103.  * 
  104.  * Revision 1.12  1993/11/08  16:21:42  john
  105.  * made stop_slew or whatever return an int
  106.  * 
  107.  * Revision 1.11  1993/11/01  13:59:49  john
  108.  * more slew experiments.
  109.  * 
  110.  */
  111.  
  112. #include <stdlib.h>
  113.  
  114. #include "inferno.h"
  115. #include "game.h"
  116. #include "vecmat.h"
  117. #include "key.h"
  118. #include "joy.h"
  119. #include "object.h"
  120. #include "error.h"
  121. #include "physics.h"
  122. #include "joydefs.h"
  123. #include "kconfig.h"
  124.  
  125. #pragma off (unreferenced)
  126. static char rcsid[] = "$Id: slew.c,v 1.1.1.1 1998/03/03 15:12:30 nobody Exp $";
  127. #pragma on (unreferenced)
  128.  
  129. //variables for slew system
  130.  
  131. object *slew_obj=NULL;    //what object is slewing, or NULL if none
  132.  
  133. #define JOY_NULL 15
  134. #define ROT_SPEED 8        //rate of rotation while key held down
  135. #define VEL_SPEED (2*55)    //rate of acceleration while key held down
  136.  
  137. short old_joy_x,old_joy_y;    //position last time around
  138.  
  139. //say start slewing with this object
  140. slew_init(object *obj)
  141. {
  142.     slew_obj = obj;
  143.  
  144.     slew_obj->control_type = CT_SLEW;
  145.     slew_obj->movement_type = MT_NONE;
  146.  
  147.     slew_stop();        //make sure not moving
  148. }
  149.  
  150.  
  151. int slew_stop()
  152. {
  153.     if (!slew_obj || slew_obj->control_type!=CT_SLEW) return 0;
  154.  
  155.     vm_vec_zero(&slew_obj->mtype.phys_info.velocity);
  156.     return 1;
  157. }
  158.  
  159. void slew_reset_orient()
  160. {
  161.     if (!slew_obj || slew_obj->control_type!=CT_SLEW) return;
  162.  
  163.     slew_obj->orient.rvec.x = slew_obj->orient.uvec.y = slew_obj->orient.fvec.z = f1_0;
  164.  
  165.     slew_obj->orient.rvec.y = slew_obj->orient.rvec.z = slew_obj->orient.uvec.x = 
  166.    slew_obj->orient.uvec.z = slew_obj->orient.fvec.x = slew_obj->orient.fvec.y = 0;
  167.  
  168. }
  169.  
  170. int do_slew_movement(object *obj, int check_keys, int check_joy )
  171. {
  172.     int moved = 0;
  173.     vms_vector svel, movement;                //scaled velocity (per this frame)
  174.     vms_matrix rotmat,new_pm;
  175.     int joy_x,joy_y,btns;
  176.     int joyx_moved,joyy_moved;
  177.     vms_angvec rotang;
  178.  
  179.     if (!slew_obj || slew_obj->control_type!=CT_SLEW) return 0;
  180.  
  181.     if (check_keys) {
  182.         if (Function_mode == FMODE_EDITOR) {
  183.             obj->mtype.phys_info.velocity.x += VEL_SPEED * (key_down_time(KEY_PAD9) - key_down_time(KEY_PAD7));
  184.             obj->mtype.phys_info.velocity.y += VEL_SPEED * (key_down_time(KEY_PADMINUS) - key_down_time(KEY_PADPLUS));
  185.             obj->mtype.phys_info.velocity.z += VEL_SPEED * (key_down_time(KEY_PAD8) - key_down_time(KEY_PAD2));
  186.  
  187.             rotang.p = (key_down_time(KEY_LBRACKET) - key_down_time(KEY_RBRACKET))/ROT_SPEED ;
  188.             rotang.b  = (key_down_time(KEY_PAD1) - key_down_time(KEY_PAD3))/ROT_SPEED;
  189.             rotang.h  = (key_down_time(KEY_PAD6) - key_down_time(KEY_PAD4))/ROT_SPEED;
  190.         }
  191.         else {
  192.             obj->mtype.phys_info.velocity.x += VEL_SPEED * Controls.sideways_thrust_time;
  193.             obj->mtype.phys_info.velocity.y += VEL_SPEED * Controls.vertical_thrust_time;
  194.             obj->mtype.phys_info.velocity.z += VEL_SPEED * Controls.forward_thrust_time;
  195.  
  196.             rotang.p = Controls.pitch_time/ROT_SPEED ;
  197.             rotang.b  = Controls.bank_time/ROT_SPEED;
  198.             rotang.h  = Controls.heading_time/ROT_SPEED;
  199.         }
  200.     }
  201.     else
  202.         rotang.p = rotang.b  = rotang.h  = 0;
  203.  
  204.     //check for joystick movement
  205.  
  206.     if (check_joy && joy_present && (Function_mode == FMODE_EDITOR) )    {
  207.         joy_get_pos(&joy_x,&joy_y);
  208.         btns=joy_get_btns();
  209.     
  210.         joyx_moved = (abs(joy_x - old_joy_x)>JOY_NULL);
  211.         joyy_moved = (abs(joy_y - old_joy_y)>JOY_NULL);
  212.     
  213.         if (abs(joy_x) < JOY_NULL) joy_x = 0;
  214.         if (abs(joy_y) < JOY_NULL) joy_y = 0;
  215.     
  216.         if (btns)
  217.             if (!rotang.p) rotang.p = fixmul(-joy_y * 512,FrameTime); else;
  218.         else
  219.             if (joyy_moved) obj->mtype.phys_info.velocity.z = -joy_y * 8192;
  220.     
  221.         if (!rotang.h) rotang.h = fixmul(joy_x * 512,FrameTime);
  222.     
  223.         if (joyx_moved) old_joy_x = joy_x;
  224.         if (joyy_moved) old_joy_y = joy_y;
  225.     }
  226.  
  227.     moved = rotang.p | rotang.b | rotang.h;
  228.  
  229.     vm_angles_2_matrix(&rotmat,&rotang);
  230.     vm_matrix_x_matrix(&new_pm,&obj->orient,&rotmat);
  231.     obj->orient = new_pm;
  232.     vm_transpose_matrix(&new_pm);        //make those columns rows
  233.  
  234.     moved |= obj->mtype.phys_info.velocity.x | obj->mtype.phys_info.velocity.y | obj->mtype.phys_info.velocity.z;
  235.  
  236.     svel = obj->mtype.phys_info.velocity;
  237.     vm_vec_scale(&svel,FrameTime);        //movement in this frame
  238.     vm_vec_rotate(&movement,&svel,&new_pm);
  239.  
  240. //    obj->last_pos = obj->pos;
  241.     vm_vec_add2(&obj->pos,&movement);
  242.  
  243.     moved |= (movement.x || movement.y || movement.z);
  244.  
  245.     if (moved) 
  246.         update_object_seg(obj);    //update segment id
  247.  
  248.     return moved;
  249. }
  250.  
  251. //do slew for this frame
  252. int slew_frame(int check_keys)
  253. {
  254.     return do_slew_movement( slew_obj, !check_keys, 1 );
  255.  
  256. }
  257.